<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of gmmsample</title>
  <meta name="keywords" content="gmmsample">
  <meta name="description" content="GMMSAMPLE  Draw N samples from the Gaussian mixture model (GMM) described by the">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../menu.html">Home</a> &gt;  <a href="#">ReBEL-0.2.7</a> &gt; <a href="#">core</a> &gt; gmmsample.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../menu.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="menu.html">Index for .\ReBEL-0.2.7\core&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>gmmsample
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>GMMSAMPLE  Draw N samples from the Gaussian mixture model (GMM) described by the</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [X,comp] = gmmsample(gmmDS, N) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment"> GMMSAMPLE  Draw N samples from the Gaussian mixture model (GMM) described by the
            GMM data structure 'gmmDS'.

   [X,comp] = gmmsample(gmmDS, N)

   INPUT
          gmmDS         Gaussian mixture model data structure with the following fields
            .cov_type   covariance matrix type 'full' , 'diag' , 'sqrt' , 'sqrt-diag'    [string]
            .dim        data dimension  [scalar]
            .M          number of Gaussian component densities  [scalar]
            .weights    mixing priors (component weights) [1-by-M matrix]
            .mu         M Gaussian component means (columns of matrix) [dim-by-M matrix]
            .cov        covariance matrices of Gaussian components (must comply with .cov_type)
                        [dim-by-dim-by-N matrix]
          N             number of samples to generate [scalar]
   OUTPUT
          X             buffer of N samples drawn from the GMM  [dim-by-N matrix]
          comp          component index of samples [1-by-N vector]

   See also
     GMMEVAL
   Copyright (c) Oregon Health &amp; Science University (2006)

   This file is part of the ReBEL Toolkit. The ReBEL Toolkit is available free for
   academic use only (see included license file) and can be obtained from
   http://choosh.csee.ogi.edu/rebel/.  Businesses wishing to obtain a copy of the
   software should contact rebel@csee.ogi.edu for commercial licensing information.

   See LICENSE (which should be part of the main toolkit distribution) for more
   detail.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="gennoiseds.html" class="code" title="function NoiseDS = gennoiseds(ArgDS)">gennoiseds</a>	GENNOISEDS    Generates a NoiseDS data structure describing a noise source.</li><li><a href="gmsppf.html" class="code" title="function [estimate, ParticleFilterDS, pNoise, oNoise, extra] = gmsppf(ParticleFilterDS, pNoise, oNoise, obs, U1, U2, InferenceDS)">gmsppf</a>	GMSPPF  Gaussian Mixture Sigma-Point Particle Filter</li></ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [X,comp] = gmmsample(gmmDS, N)</a>
0002 
0003 <span class="comment">% GMMSAMPLE  Draw N samples from the Gaussian mixture model (GMM) described by the</span>
0004 <span class="comment">%            GMM data structure 'gmmDS'.</span>
0005 <span class="comment">%</span>
0006 <span class="comment">%   [X,comp] = gmmsample(gmmDS, N)</span>
0007 <span class="comment">%</span>
0008 <span class="comment">%   INPUT</span>
0009 <span class="comment">%          gmmDS         Gaussian mixture model data structure with the following fields</span>
0010 <span class="comment">%            .cov_type   covariance matrix type 'full' , 'diag' , 'sqrt' , 'sqrt-diag'    [string]</span>
0011 <span class="comment">%            .dim        data dimension  [scalar]</span>
0012 <span class="comment">%            .M          number of Gaussian component densities  [scalar]</span>
0013 <span class="comment">%            .weights    mixing priors (component weights) [1-by-M matrix]</span>
0014 <span class="comment">%            .mu         M Gaussian component means (columns of matrix) [dim-by-M matrix]</span>
0015 <span class="comment">%            .cov        covariance matrices of Gaussian components (must comply with .cov_type)</span>
0016 <span class="comment">%                        [dim-by-dim-by-N matrix]</span>
0017 <span class="comment">%          N             number of samples to generate [scalar]</span>
0018 <span class="comment">%   OUTPUT</span>
0019 <span class="comment">%          X             buffer of N samples drawn from the GMM  [dim-by-N matrix]</span>
0020 <span class="comment">%          comp          component index of samples [1-by-N vector]</span>
0021 <span class="comment">%</span>
0022 <span class="comment">%   See also</span>
0023 <span class="comment">%     GMMEVAL</span>
0024 <span class="comment">%   Copyright (c) Oregon Health &amp; Science University (2006)</span>
0025 <span class="comment">%</span>
0026 <span class="comment">%   This file is part of the ReBEL Toolkit. The ReBEL Toolkit is available free for</span>
0027 <span class="comment">%   academic use only (see included license file) and can be obtained from</span>
0028 <span class="comment">%   http://choosh.csee.ogi.edu/rebel/.  Businesses wishing to obtain a copy of the</span>
0029 <span class="comment">%   software should contact rebel@csee.ogi.edu for commercial licensing information.</span>
0030 <span class="comment">%</span>
0031 <span class="comment">%   See LICENSE (which should be part of the main toolkit distribution) for more</span>
0032 <span class="comment">%   detail.</span>
0033 
0034 <span class="comment">%=============================================================================================</span>
0035 
0036 dim   = gmmDS.dim;                         <span class="comment">% random vector dimension</span>
0037 Ncomp = gmmDS.M;                           <span class="comment">% number of component densities</span>
0038 w     = gmmDS.weights(:);                  <span class="comment">% prior mixing probabilities</span>
0039 mu    = gmmDS.mu;                          <span class="comment">% component means</span>
0040 cov   = gmmDS.cov;                         <span class="comment">% component covariance matrices</span>
0041 
0042 u    = rand(1,N);
0043 
0044 [Nc,comp] = histc(u, cumsum([0; w]));      <span class="comment">% draw component indices according to prior</span>
0045                                            <span class="comment">% probabilities specified in gmmDS.weights</span>
0046                                            <span class="comment">% Nc = number of samples in each component</span>
0047                                            <span class="comment">% comp = index vector</span>
0048 
0049 X = zeros(dim, N);
0050 
0051 <span class="comment">% Sample each component according to the prior probabilities</span>
0052 <span class="keyword">switch</span> gmmDS.cov_type
0053 
0054    <span class="comment">%----------------------------------------------------------------------</span>
0055    <span class="keyword">case</span> {<span class="string">'full'</span>,<span class="string">'diag'</span>}
0056 
0057    <span class="keyword">for</span> k=1:Ncomp,
0058       idx = find(comp==k);
0059       X(:,idx) = chol(cov(:,:,k))' * randn(dim,Nc(k));
0060    <span class="keyword">end</span>
0061 
0062    <span class="comment">%----------------------------------------------------------------------</span>
0063    <span class="keyword">case</span> {<span class="string">'sqrt'</span>,<span class="string">'sqrt-diag'</span>}
0064 
0065       <span class="keyword">for</span> k=1:Ncomp,
0066           idx = find(comp==k);
0067           X(:,idx) = cov(:,:,k) * randn(dim,Nc(k));
0068       <span class="keyword">end</span>
0069 
0070   <span class="keyword">otherwise</span>
0071     error(<span class="string">' [ gmmsample ] Unknown covariance type!'</span>);
0072 
0073 <span class="keyword">end</span>
0074 
0075 X = X + mu(:,comp);     <span class="comment">% add in means</span></pre></div>
<hr><address>Generated on Tue 26-Sep-2006 10:36:21 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>